package com.example.sprintbootarithmetic.DataStructure.arrayQueue;

public class Queue {
    private int reem;// �����ָ��
    private int front;// ǰ���ָ��
    private int maxsize;
    private int[] array;

    public Queue(int arrMaxsize) {
        array = new int[arrMaxsize];
        maxsize = arrMaxsize;
        this.reem = -1;
        this.front = -1;
    }

    public boolean isair() {// �ж��Ƿ�Ϊ��
        return reem == front;
    }

    public boolean isfull() {// �ж��Ƿ��Ѿ�����
        return reem == maxsize - 1;
    }

    public String additem(int j) {
        if (!isfull()) {
            System.out.println("�����ݶ�");
            this.front++;
            this.array[front] = j;
            return "��ӳɹ�";
        } else {
            throw new RuntimeException("��������,�����������");
        }

    }

    public Object getitem() {// ����
        if (!isair()) {
            this.reem++;
            return array[reem];
        }
        return new RuntimeException("�Բ���,����Ϊ�գ����ܳ���");
    }

    public Object getfirst() {
        if (!isair()) {
            return array[front + 1];
        } else {
            return new RuntimeException("�Բ���,����Ϊ��,����ȡ����һ������");
        }
    }

    public Object getlast() {
        if (!isair()) {
            return array[reem + 1];
        } else {
            return new RuntimeException("����Ϊ�գ�û����Ϣ");
        }
    }

    public void getall() {
        if (!isair()) {
            for (int i = reem; reem < array.length; reem++) {
                System.out.println(array[reem]);
            }
        } else {
            throw new RuntimeException("����Ϊ�գ�û����Ϣ");
        }
    }
}
